//
//  ViewController.m
//  Array_null
//
//  Created by JonyFang on 16/5/9.
//  Copyright © 2016年 JonyFang. All rights reserved.
//

#import "ViewController.h"
#import "BaseEntity.h"

@interface ViewController ()
@property (nonatomic, strong) NSMutableArray *array;

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    [self configureArray];
    [self testCurrentArray];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

- (void)configureArray
{
    NSDictionary *dictionary = [self dictionaryWithContentsOfJSONString:@"person.json"];
    
//    //nil
//    self.array = [BaseEntity arrayOfEntitiesFromArray:dictionary[@"person"]].mutableCopy;
    
    //null
    self.array = [dictionary objectForKey:@"person"];
}

- (NSDictionary *)dictionaryWithContentsOfJSONString:(NSString *)fileLocation
{
    NSString *filePath = [[NSBundle mainBundle] pathForResource:[fileLocation stringByDeletingPathExtension] ofType:@"json"];
    NSData *data = [NSData dataWithContentsOfFile:filePath];
    __autoreleasing NSError *error = nil;
    id result = [NSJSONSerialization JSONObjectWithData:data
                                                options:NSJSONReadingMutableContainers error:&error];
    if (error != nil) return nil;
    return result;
}

#pragma mark - test

- (void)testCurrentArray
{
    if ([self.array isKindOfClass:[NSNull class]])
    {
        NSLog(@"array is a kind of NSNull class");
    }
    else
    {
        NSLog(@"error");
    }
    
    if (self.array.count > 0)
    {
        NSLog(@"array.count > 0");
    }
    else
    {
        NSLog(@"array.count error");
    }
}

@end
